#ifndef MY_SEVER_H
#define MY_SEVER_H
#include "server.h"
#include "db.h"
#include "json.hpp"
#include <curl/curl.h>
#include <stdlib.h>
#include <iostream>
#include "cmd.h"
#include <map>
#include "user.h"

#define QUESTIONNUM 5
using json = nlohmann::json;
class my_sever:public Tcpserver
{
public:
      my_sever(int num=8);
      void readEvent(Tcpsocket*s);
      void writeEvent(Tcpsocket*s);
      void closeEvent(Tcpsocket*s,short what);
      void connectEvent(Tcpsocket*s);
      void initrankMap();

private:
      void Register(Tcpsocket *s,json& j);
      void writeData(Tcpsocket *s,json& j);
      void Login(Tcpsocket *s,json& j);
      void singleGetQ(Tcpsocket*s,json&j);
      //出理rank题目同步
      void  rankAnswerQ(Tcpsocket*s,json&j);
      //rank结果
        void rankResult(Tcpsocket*s,json&j);
       //排位
      void Rank(Tcpsocket*s,json&j);
      //开始对决
      void startRank(Tcpsocket*first,Tcpsocket*second);
      DB*db;//数据库对象
      //rank转换表
      std::map<int,string> rankMap;
      std::mutex userLock;
      std::mutex rankLock;
      std::map<std::string,User*> users;//在线用户列表
      std::map<int,Tcpsocket*> rankQueue;//等待排位的队列
};

#endif // MY_SEVER_H
